<template>
	<view class="recharge page">
		<view class="user-info">
			<image class="avatar" :src="user.avatar"></image>
			<text class="name">{{user.name}} {{user.code}}</text>
		</view>
		<view class="form">
			<text class="label">充值金额</text>
			<view class="inp">
				<text class="icon">￥</text>
				<input v-model="amount" type="text" class="input">
			</view>
			
		</view>
		
		<view class="btn" @click="recharge">
			确认充值
		</view>
		
		<view class="provision">
			充值协议:{{provision}}
		</view>
		
	</view>
</template>

<script>
	import {getUserInfo,recharge} from '@/api/user.js' 
	import {showError} from '@/toast/index.js'
	import {showCorrect} from '@/modal/index.js'
	export default {
		onShow() {
			getUserInfo().then(res => {
				this.user = res.data
			})
		},
		methods:{
			recharge(){
				if(this.amount>0){
					recharge(this.amount).then(res=>{
						let ob = JSON.parse(res.data)
						uni.requestPayment({
							success:()=>{
								this.clearCart()
								showCorrect("支付成功").then(res => {
									// this.$Router.back()
								})
							},
							complete:()=>{
								this.$Router.back()
							},
							fail: (res) => {
								showError("取消支付!")
								// this.$Router.back()
							},
							...ob
						})
					})
				}
			}
		},
		data() {
			return {
				amount:200,
				user:{},
				provision:getApp().globalData.config.provision
			};
		}
	}
</script>

<style lang="stylus">
	.recharge
		background url(../../static/hbg.png) no-repeat
		background-size 100% 190upx
		background-color #FFFFFF
		padding 0 20upx
		.user-info
			height 190upx
			display flex
			flex-direction column
			align-items center
			justify-content center
			.avatar
				width 80upx
				height 80upx
				border-radius 10upx
				margin-bottom 18upx
			.name
				color white
				font-size 28upx
		.form
			margin-top 50upx
			width 630upx
			.label
				font-size 24upx
				color #4E3D07
				margin-bottom 60upx
			.inp
				display flex
				height 100upx
				border-bottom 1px solid #DCDCDC
				.icon
					font-size 72upx
					color #4E3D07
				.input
					font-size 50upx
					padding-left 60upx
					height 100%
					outline none
					border none
		.btn
			width 100%
			height:88upx;
			background:rgba(247,137,94,1);
			border-radius:15upx;
			display flex
			align-items center
			justify-content center
			color white
			margin-top 80upx
		.provision
			margin-top 20upx
			font-size 28upx
			color #6F6F6F
</style>
